package com.ccjq.shosestore.web.controller.product;

import com.ccjq.shosestore.core.utils.PageBean;
import com.ccjq.shosestore.core.utils.PageHelper;
import com.ccjq.shosestore.product.bo.Product;
import com.ccjq.shosestore.product.service.ProductService;
import com.ccjq.shosestore.product.service.impl.ProductServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "ProductCLServlet")
public class ProductCLServlet extends HttpServlet {
    private ProductService pr=new ProductServiceImpl();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
     String action=request.getParameter("action");
     System.out.print(action);
     if(action.equals("pp"))
     {
         String catid=request.getParameter("catid");
         int a=pr.zhs(catid);
         PageBean p= PageHelper.getPager(request,a);
         List<Product> list=pr.pinpaiAll(p.getStartRow(), p.getPageSize(),catid);
         request.getSession().setAttribute("list1",list);
         request.getSession().setAttribute("catid",catid);
         request.getRequestDispatcher("WEB-INF/jsp/product/product_list.jsp").forward(request,response);
     }
     if(action.equals("fenye2"))
     {
        String catid=(String)request.getSession().getAttribute("catid");
        int a=pr.zhs(catid);
         PageBean p= PageHelper.getPager(request,a);
         List<Product> list=pr.pinpaiAll(p.getStartRow(), p.getPageSize(),catid);
         request.getSession().setAttribute("pageBean",p);
         request.getSession().setAttribute("list1",list);
         request.getRequestDispatcher("WEB-INF/jsp/product/product_list.jsp").forward(request,response);
     }
     if(action.equals("xq"))
     {
         String prid=request.getParameter("prid");
         Product product=pr.details(prid);
         request.getSession().setAttribute("product",product);
         request.getRequestDispatcher("WEB-INF/jsp/product/product_detail.jsp").forward(request,response);
     }

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
